package com.example.lx6_1.area

import androidx.lifecycle.viewModelScope
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.example.base.entity.AreaEntityItem
import com.example.base.mvvm.BaseViewModel
import com.example.base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

@HiltViewModel
class AreaViewModel @Inject constructor(val apiService: ApiService) : BaseViewModel() {

    fun getArea():Flow<PagingData<AreaEntityItem>>{
        return Pager(config = PagingConfig(pageSize = 10), pagingSourceFactory = {
            AreaSource(apiService)
        }).flow.cachedIn(viewModelScope)
    }

}